package com.andnnl.act.beetlsql.base;

import act.Act;
import act.controller.annotation.UrlContext;
import act.db.beetlsql.BeetlSqlTransactional;
import org.osgl.http.H;
import org.osgl.mvc.annotation.GetAction;
import org.osgl.mvc.annotation.ResponseContentType;
import org.osgl.mvc.annotation.With;
import org.slf4j.Logger;

import javax.inject.Inject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static act.controller.Controller.Util.redirect;
import static act.controller.Controller.Util.render;

/**
 * A Simple Todo application controller
 */
@SuppressWarnings("unused")
@UrlContext("/emas")
@With(BeetlSqlTransactional.class)
public class Emas {

    @Inject
    EmasUcinfoDao emasUcinfoDao;

    public static void main(String[] args) throws Exception {
        Act.start("TODO-BeetlSql");
    }

    @GetAction
    public void index() {
        String title = "Act+BeetlSQL";


        Map<String, Object> paras = new HashMap<>();
//        paras.put("uid", "andnnl");
        List<EmasUcinfo> list= emasUcinfoDao.getSQLManager().
                select("emasUcinfo.sample", EmasUcinfo.class, paras, 1L, 10L);
        System.out.println("classInt:"+list.get(0).getClassInt());
        render(title,list);
    }

    @GetAction("list")
    @ResponseContentType(H.MediaType.JSON)
    public List<EmasUcinfo> list() {
        Map<String, Object> paras = new HashMap<>();
//        paras.put("uid", "andnnl");
        return emasUcinfoDao.getSQLManager().select("emasUcinfo.sample", EmasUcinfo.class, paras, 1L, 10L);
    }


}
